import std.stdio;
import std.conv;
import std.string;

void main()
{
    string did = "4B790BC8-376E-467B-9142-2AE0D158650D";
    string tdid = did.replace("-","");
    writeln("tdid is :  ", tdid.length);
    writeln("tdid is :  ", tdid);
    
    string str  = formHexString(tdid);
    writeln("str  is ", str.length);
    writeln("str  is ", str);
}

string formHexString(string hexData)
{
    import std.ascii;
    
    char[] result;
    result.length = hexData.length / 2;
    size_t cnt;
    ubyte v;
    foreach (char c; hexData)
    {
        if (c.isHexDigit)
        {
            ubyte x;
            if (c >= '0' && c <= '9')
                x = cast(ubyte)(c - '0');
            else if (c >= 'a' && c <= 'f')
                x = cast(ubyte)(c - ('a' - 10));
            else if (c >= 'A' && c <= 'F')
                x = cast(ubyte)(c - ('A' - 10));
            if (cnt & 1)
            {
                v = cast(ubyte)((v << 4) | x);
                result[cnt / 2] = v;
            }
            else
                v = x;
            ++cnt;
        }
    }
    result.length = cnt / 2;
    return cast(string)result;
}
